//
//  LittleBallPlayViewController.h
//  LittleBall
//
//  Created by mac on 11-12-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <QuartzCore/CoreAnimation.h>
#import "LittleBallGameManagement.h"
#import "LBBall.h"
#import "LBPathFinder.h"
#import "LBMoveAnimationDelegate.h"
#import "LBShowCurrentScoreAnimationDelegate.h"
#import "LBBallSelectedAnimationDelegate.h"
#import "LittleBallPropertyViewController.h"
#import "LBPropertiesCommon.h"


#define LB_BOMB_BASE_NUM        5

@interface LittleBallPlayViewController : UIViewController
{
    IBOutlet UIImageView  *m_backgroundView;
    IBOutlet UIButton     *m_gamePause;
    IBOutlet UIButton     *m_goBack;
    IBOutlet UILabel      *m_timeLabel;
    IBOutlet UILabel      *m_scoreLabel;
    IBOutlet UILabel      *m_currentScoreLabel;
    IBOutlet UILabel      *m_honor;
    
    UIImageView           *m_pauseView;
    
    UIImage               *m_imageArrary[BALL_COLOR_NUM];
    NSMutableArray        *m_ballArray;
    LBBall                *m_prevSelectedBall;
    
    NSTimer               *m_timer;

    NSMutableArray        *m_newPositions;
    LBPathFinder          *m_pathFinder;
    LBPathFinder          *m_pathFinder2;
    
    AVAudioPlayer         *m_soundEffectsPlayer;
    NSError               *m_nsErrForSoundEffectsPlayer;
    AVAudioPlayer         *m_backGroundSoundPlayer;
    NSError               *m_nsErrForbackGroundSoundPlayer;
    
    UIAlertView           *m_loseAlert;
    
    LBPosition            *startPosition1;
    LBPosition            *endPosition1;
    
    LBShowCurrentScoreAnimationDelegate *m_showCurrentScoreAnimationDelegate;
    LBMoveAnimationDelegate *m_ballMoveAnimationDelegate;
    LBMoveAnimationDelegate *m_ballMoveAnimationDelegate2;
    LBBallSelectedAnimationDelegate *m_ballSelectedAnimationDelegate;
    
    AVAudioPlayer         *m_soundEffectsPlayerInPlayView;
    AVAudioPlayer         *m_backGroundSoundPlayerInPlayView;    
    
    GAME_MODE             gameMode;
    BOOL                  gamePause;
    
    int                   timeSeconds;    
    int                   gameScore;
    
    int                   randomBallGenNum;
    int                   initNumberForTraditional;

    BOOL                  simultaneityFlag;
    
    NSMutableArray        *nextBallColorArray;
    NSMutableArray        *nextBallLittlePicArray;
    
    LittleBallGameManagement  *m_gameManagement;
    
    // 道具
    LittleBallPropertyViewController *m_propertyViewController;
    
    // 道具释放动画播放记时
    BOOL                m_bPropertyPlaying; // 道具释放中状态
    NSTimer             *m_timer_property; // 道具动画效果计时器

}

- (IBAction)onButton_gamePause:(id)sender;
- (IBAction)onButton_goBack:(id)sender;

- (void)initializePlayView;
- (void)setGameMode:(GAME_MODE)input;
- (void)setGameConfiguration;

- (void)startGame;
- (void)onTimer;

- (enum LBErrorCodeType)createBallWithColor:(BALL_COLOR)color atRow:(int)row atColumn:(int)column;
- (BOOL)checkPositionEmptyAtRow:(int)row atColumn:(int)column;
- (void)generateNewBalls;
- (LBBall*)getBallByRow:(int)row column:(int)column;
- (void)showCurrentScoreWithScore:(int)score withLabel:(UILabel *)label withCenterPoint:(CGPoint)centerPoint;

- (BOOL)clearBallsWithBall:(LBBall *)ball;
- (void)destroyBall:(LBBall *)ball;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

- (LBBall*)getBallByTouchPoint:(CGPoint)touchPoint;

- (void)selectABallAtRow:(int)row atColumn:(int)column;
- (void)unSelectBall;
- (void)unSelectABallAtRow:(int)row atColumn:(int)column;
- (void)moveBall:(LBBall *)ball byPath:(NSMutableArray *)path;

- (void)setFlag:(BOOL)input;

- (GAME_MODE)getGameMode;
- (int)getGameDifficluty;
- (void)setGameMode:(GAME_MODE)input;

- (void)gameOver;
- (void)resetGame;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

- (void)clearPreShowInfo;

//- (void)alertViewCancel:(UIAlertView *)alertView;
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

// 道具施放
- (BOOL)bomb:(LBBomb *)bomb;
- (void)releaseBombEmittersWithBomb:(LBBomb *)bomb;
- (void)setFireAmount:(int)damage;


@property (retain, nonatomic) id m_gameManagement;
@property int gameScore;

// 炸弹效果粒子
@property (strong) CAEmitterLayer *coreEmitter;
@property (strong) CAEmitterLayer *fireEmitter;
@property (strong) CAEmitterLayer *smokeEmitter;
//@property (strong) CAEmitterLayer *fireEmitter_down;
//@property (strong) CAEmitterLayer *smokeEmitter_down;
//@property (strong) CAEmitterLayer *fireEmitter_left;
//@property (strong) CAEmitterLayer *smokeEmitter_left;
//@property (strong) CAEmitterLayer *fireEmitter_right;
//@property (strong) CAEmitterLayer *smokeEmitter_right;

- (void)refreshScoreDisplay;

@end
